var __assign =
  (this && this.__assign) ||
  function () {
    __assign =
      Object.assign ||
      function (t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
          s = arguments[i];
          for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
        }
        return t;
      };
    return __assign.apply(this, arguments);
  };
import React, { useEffect, useRef, useState } from 'react';
import { createMenuItem } from '../utils/createMenuItem';
import { registerItemStore } from '../utils/registerItemStore';
import { ConfigContextProvider, useConfigContext } from './contexts/ConfigContext';
import LeggoLeft from './LeggoLeft';
import LeggoMiddle from './LeggoMiddle';
import LeggoRight from './LeggoRight';
export var ConfigsContext = React.createContext(null);
export function LeggoConfigsInner(props) {
  var _a = useConfigContext(),
    setItemStore = _a.setItemStore,
    setSchemaModel = _a.setSchemaModel,
    setForceRender = _a.setForceRender,
    setActiveSchema = _a.setActiveSchema;
  var onGetSchemaModel = props.onGetSchemaModel,
    _b = props.fieldList,
    fieldList = _b === void 0 ? [] : _b,
    formSchema = props.formSchema;
  var activeSchema = useRef(null);
  var _c = useState(0),
    count = _c[0],
    setForceRenderFunc = _c[1];
  useEffect(function () {
    setActiveSchema(activeSchema);
    setForceRender(function () {
      return setForceRenderFunc(function (pre) {
        return pre + 1;
      });
    });
  }, []);
  useEffect(
    function () {
      setSchemaModel(onGetSchemaModel);
    },
    [onGetSchemaModel]
  );
  useEffect(
    function () {
      if (fieldList.length > 0) {
        setItemStore(createMenuItem(fieldList));
      }
    },
    [fieldList]
  );
  return React.createElement(
    'div',
    { className: 'leggo-configs' },
    React.createElement(LeggoLeft, null),
    React.createElement(LeggoMiddle, { formSchema: formSchema }),
    React.createElement(LeggoRight, null)
  );
}
export function LeggoConfigs(props) {
  return React.createElement(
    ConfigContextProvider,
    null,
    React.createElement(LeggoConfigsInner, __assign({}, props))
  );
}
LeggoConfigs.registerItemStore = function (itemStore) {
  registerItemStore(itemStore);
  console.log(LeggoConfigs.name);
};
